//
//  QRcodeViewController.m
//  RENTVISITOR
//
//  Created by wonder on 2017/8/22.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "QRcodeViewController.h"
#import "RentVieitor.h"
#import <CoreImage/CoreImage.h>


@interface QRcodeViewController ()

@end

@implementation QRcodeViewController

- (void)viewWillAppear:(BOOL)animated {
    
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"推荐二维码";
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatLeftView];
    [self creatView];
}

- (void)creatLeftView {
    
    // 自定义导航栏左侧按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 10,15 );
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"箭头左"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
}

- (void)creatView {
    
    
    //number会员编号
    NSDictionary *dataDic = User_listsValue;
    NSString *rUrl = [NSString stringWithFormat:@"%@%@",RURL,dataDic[@"number"]];
    
    // 1. 创建一个二维码滤镜实例(CIFilter)
    CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
    // 滤镜恢复默认设置
    [filter setDefaults];
    
    // 2. 给滤镜添加数据

    NSData *data = [rUrl dataUsingEncoding:NSUTF8StringEncoding];
    // 使用KVC的方式给filter赋值
    [filter setValue:data forKeyPath:@"inputMessage"];
    
    // 3. 生成二维码
    CIImage *image = [filter outputImage];
    
    // 4. 显示二维码
   

    UIImageView *logoView = [[UIImageView alloc] initWithFrame:CGRectMake((KWidth-160)/2, 160, 160, 160)];
    logoView.image = [UIImage imageWithCIImage:image];
    [self.view addSubview:logoView];
    
    //租客网
    UIImageView *imgView =  [[UIImageView alloc] initWithFrame:CGRectMake((KWidth-90)/2, 60, 90, 30)];
    imgView.image = [UIImage imageNamed:@"租客网"];
    [self.view addSubview:imgView];
    
    UILabel *selectLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, KWidth-40, 30)];
    selectLabel.text = @"好生活,租着过";
    selectLabel.font = [UIFont systemFontOfSize:17];
    selectLabel.textAlignment = NSTextAlignmentCenter;
    selectLabel.textColor = [Utils colorConvertFromString:@"#333333"];
    [self.view addSubview:selectLabel];
    
    //分割线
    CALayer *MlineLayer7 = [CALayer layer];
    MlineLayer7.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
    MlineLayer7.frame = CGRectMake(0 ,530, KWidth, 1);
    [self.view.layer addSublayer:MlineLayer7];
    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    UILabel *vesLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 550, KWidth-40,20)];
    vesLabel.text =  [NSString stringWithFormat:@"版本号: %@",app_Version]; 
    vesLabel.font = [UIFont systemFontOfSize:13];
    vesLabel.textAlignment = NSTextAlignmentCenter;
    vesLabel.textColor = [Utils colorConvertFromString:@"#333333"];
    [self.view addSubview:vesLabel];

}

- (void)backAction {
    
    [self.navigationController popViewControllerAnimated:YES];
}

@end
